#include "dyn_ode_rk4.h"

RK4::RK4(MultiFunctor &func,
         colvec _initCond,
         double _start,
         double _end,
         double _initStepsize)
    : ODE(func,_initCond,_start,_end,_initStepsize)
{
}

colvec RK4::next(colvec previousStep)
{
    colvec k1 = initStepsize*integrand(previousStep);
    colvec k2 = initStepsize*integrand(previousStep+0.5*k1);
    colvec k3 = initStepsize*integrand(previousStep+0.5*k2);
    colvec k4 = initStepsize*integrand(previousStep+k3);

    double sixth = 1.0/6.0;
    double third = 1.0/3.0;

    return previousStep+sixth*k1+third*k2+third*k3+sixth*k4;
}
